{% extends 'app01/admin/home.html' %}

{% block content %}
    <div class="panel panel-default">
        <div class="panel-heading">学生管理</div>
        <div class="panel-body">
            <div class="container">
                <div class="row">
                    <div class="col-md-6 col-md-offset-3">
                        <br>
                        <div> 管理员账户：<input type="text" id="admin_id" value="admin512xxxx" class="form-control"></div>
                        <div> 管理员手机：<input type="text" id="phone_id" class="form-control"></div>
                        <div>email: <input type="text" id="phone_id" class="form-control"></div>
                        <div> 密码：<input type="password" id="pwd" class="form-control"></div>
                         <div> 密码：<input type="password" id="pwd_agan" class="form-control"></div>
                        <div> <button id="btn_id" class="'btn btn-block btn-primary">提交</button></div>
                    </div>
                </div>
            </div>

        </div>
    </div>
{% endblock %}

{% block js %}
    <script>

        //设置一个鼠标聚焦事件。
        $('#admin_id').focus(function () {
            $('#admin_id').val('')
        })
        //修改密码的ajax请求

        $('#id_editer').click(function () {
            let old_pwd = $('#id_old_pwd').val()
            let new_pwd = $('#id_new_pwd').val()
            let comfir_pwd = $('#id_confirm_pwd').val()

            $.ajax({
                url: '/app01/set_password/',
                type: 'post',
                data: {'old_pwd': old_pwd, 'new_pwd': new_pwd, 'confirm_pwd': comfir_pwd},
                success: function (attr) {
                    if (attr.code === 1000) {
                        alert(attr.msg)
                        window.location.reload()
                    } else if (attr.code === 2000) {
                        $('#error').text(attr.msg)
                    } else if (attr.code === 3000) {
                        $('#error').text(attr.msg)
                    }
                }
            })


        });

        $('#btn_id').click(function () {
            let usernmae = $('#admin_id').val()
            let email = $('#email_id').val()
            let phone = $('#phone_id').val()
            let pwd = $('#pwd').val()
            let pwd_agan=$('#pwd_agan').val()

            $.ajax({
                url:'/app01/add_admin/',
                type:'post',
                data:{'username':usernmae,'email':email,'phone':phone,'pwd':pwd,'pwd_agan':pwd_agan},
                success:function (attr) {
                    if (attr.code===100){
                        alert(attr.msg)
                        parent.location.href=attr.url
                    }
                    else {
                        alert(attr.msg)
                    }
                }
            })
        })
    </script>
{% endblock %}